﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SP.OpenSource.CDC.Monitor
{
    public partial class DisableCDCTable : Form
    {
        public String m_sSelectedCaptureInstance = String.Empty;
        DataTable m_dtCaptureInsatnce = new DataTable();
        DataRow[] m_drCaptureInsatnce = null;
        String m_sFormTitle = "Select Instance to disable & confirm";

        public DisableCDCTable()
        {
            InitializeComponent();
        }

        public DisableCDCTable(ref DataRow[] drInCI)
        {
            InitializeComponent();

            m_drCaptureInsatnce = drInCI;

            m_dtCaptureInsatnce.Columns.Add("table_fullname");
            m_dtCaptureInsatnce.Columns.Add("capture_instance");
            
            foreach (DataRow drInNew in drInCI)
            {
                DataRow drNew = m_dtCaptureInsatnce.NewRow();
                drNew["table_fullname"] = drInNew["table_fullname"].ToString();
                drNew["capture_instance"] = drInNew["capture_instance"].ToString();
                m_dtCaptureInsatnce.Rows.Add(drNew); 
            }
            m_dtCaptureInsatnce.AcceptChanges();
            m_dtCaptureInsatnce.DefaultView.Sort = "capture_instance";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            m_sSelectedCaptureInstance = cmbSelecytCaptureInstance.Text;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            m_sSelectedCaptureInstance = String.Empty;
            this.Close();
        }

        private void DisableCDCTable_Load(object sender, EventArgs e)
        {
            if (null != m_dtCaptureInsatnce && m_dtCaptureInsatnce.Rows.Count > 0)
            {
                cmbSelecytCaptureInstance.DataSource = m_dtCaptureInsatnce;
                cmbSelecytCaptureInstance.DisplayMember = "capture_instance";
                cmbSelecytCaptureInstance.ValueMember = "capture_instance";
            }
            else
            {
                m_sSelectedCaptureInstance = String.Empty;
                MessageBox.Show("There was an issue while loading capture instance(s).", m_sFormTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
    }
}
